<?php

class Product extends AppModel
{

    var $name = 'Product';
    var $displayField = 'name';
    var $order = array('Product.name' => 'ASC');
    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'Category' => array(
            'className' => 'Category',
            'foreignKey' => 'category_id',
            'conditions' => '',
            'fields' => '',
            'order' => array('Category.name' => 'ASC')
        )
    );
    var $hasMany = array(
        'Document' => array(
            'className' => 'Document',
            'foreignKey' => 'product_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        ),
        'Potential' => array(
            'className' => 'Potential',
            'foreignKey' => 'product_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );
    var $validate = array(
        'name' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please enter product name'
            ),
            'minLength' => array(
                'rule' => array('minLength', 2),
                'message' => 'Product name should be atleast 2 characters long'
            )
        ),
        'cost' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please enter the cost of product'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'message' => 'Please enter a valid cost'
            ),
            'greaterThan' => array(
                'rule' => array('comparison', '>', 0),
                'message' => 'Product cost should be atleast 1 character long'
            )
        ),
        'costvalidfrom' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose/enter the "cost valid from" date in dd-mm-yyyy format'
            ),
            'date' => array(
                'rule' => array('date','dmy'),
                'message' => 'Please enter a valid date'
            )
        ),
        'costvalidto' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose/enter the "cost valid to" date in dd-mm-yyyy format'
            ),
            'date' => array(
                'rule' => array('date', 'dmy'),
                'message' => 'Please enter a valid date'
            )
        ),
        'category_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose the product category'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'message' => 'Please choose the product category'
            ),
            'greaterThan' => array(
                'rule' => array('comparison', '>=', 1),
                'message' => 'Please choose the product category'
            )
        )
    );

}
?>